

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>O365.message &mdash; O365  documentation</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../index.html" class="icon icon-home"> O365
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../getting_started.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../usage.html">Detailed Usage</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api.html">O365 API</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">O365</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">Module code</a> &raquo;</li>
        
      <li>O365.message</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for O365.message</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">datetime</span> <span class="k">as</span> <span class="nn">dt</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">from</span> <span class="nn">enum</span> <span class="kn">import</span> <span class="n">Enum</span>

<span class="kn">import</span> <span class="nn">pytz</span>
<span class="c1"># noinspection PyPep8Naming</span>
<span class="kn">from</span> <span class="nn">bs4</span> <span class="kn">import</span> <span class="n">BeautifulSoup</span> <span class="k">as</span> <span class="n">bs</span>
<span class="kn">from</span> <span class="nn">dateutil.parser</span> <span class="kn">import</span> <span class="n">parse</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>

<span class="kn">from</span> <span class="nn">.utils</span> <span class="kn">import</span> <span class="n">OutlookWellKnowFolderNames</span><span class="p">,</span> <span class="n">ApiComponent</span><span class="p">,</span> \
    <span class="n">BaseAttachments</span><span class="p">,</span> <span class="n">BaseAttachment</span><span class="p">,</span> <span class="n">AttachableMixin</span><span class="p">,</span> <span class="n">ImportanceLevel</span><span class="p">,</span> \
    <span class="n">TrackerSet</span><span class="p">,</span> <span class="n">Recipient</span><span class="p">,</span> <span class="n">HandleRecipientsMixin</span><span class="p">,</span> <span class="n">CaseEnum</span>
<span class="kn">from</span> <span class="nn">.calendar</span> <span class="kn">import</span> <span class="n">Event</span>
<span class="kn">from</span> <span class="nn">.category</span> <span class="kn">import</span> <span class="n">Category</span>

<span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>


<div class="viewcode-block" id="RecipientType"><a class="viewcode-back" href="../../api/message.html#O365.address_book.RecipientType">[docs]</a><span class="k">class</span> <span class="nc">RecipientType</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
    <span class="n">TO</span> <span class="o">=</span> <span class="s1">&#39;to&#39;</span>
    <span class="n">CC</span> <span class="o">=</span> <span class="s1">&#39;cc&#39;</span>
    <span class="n">BCC</span> <span class="o">=</span> <span class="s1">&#39;bcc&#39;</span></div>


<div class="viewcode-block" id="MeetingMessageType"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MeetingMessageType">[docs]</a><span class="k">class</span> <span class="nc">MeetingMessageType</span><span class="p">(</span><span class="n">CaseEnum</span><span class="p">):</span>
    <span class="n">MeetingRequest</span> <span class="o">=</span> <span class="s1">&#39;meetingRequest&#39;</span>
    <span class="n">MeetingCancelled</span> <span class="o">=</span> <span class="s1">&#39;meetingCancelled&#39;</span>
    <span class="n">MeetingAccepted</span> <span class="o">=</span> <span class="s1">&#39;meetingAccepted&#39;</span>
    <span class="n">MeetingTentativelyAccepted</span> <span class="o">=</span> <span class="s1">&#39;meetingTentativelyAccepted&#39;</span>
    <span class="n">MeetingDeclined</span> <span class="o">=</span> <span class="s1">&#39;meetingDeclined&#39;</span></div>


<div class="viewcode-block" id="Flag"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Flag">[docs]</a><span class="k">class</span> <span class="nc">Flag</span><span class="p">(</span><span class="n">CaseEnum</span><span class="p">):</span>
    <span class="n">NotFlagged</span> <span class="o">=</span> <span class="s1">&#39;notFlagged&#39;</span>
    <span class="n">Complete</span> <span class="o">=</span> <span class="s1">&#39;complete&#39;</span>
    <span class="n">Flagged</span> <span class="o">=</span> <span class="s1">&#39;flagged&#39;</span></div>


<div class="viewcode-block" id="MessageAttachment"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MessageAttachment">[docs]</a><span class="k">class</span> <span class="nc">MessageAttachment</span><span class="p">(</span><span class="n">BaseAttachment</span><span class="p">):</span>
    <span class="n">_endpoints</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;attach&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/attachments&#39;</span><span class="p">,</span>
        <span class="s1">&#39;attachment&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/attachments/</span><span class="si">{ida}</span><span class="s1">&#39;</span><span class="p">,</span>
    <span class="p">}</span></div>


<div class="viewcode-block" id="MessageAttachments"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MessageAttachments">[docs]</a><span class="k">class</span> <span class="nc">MessageAttachments</span><span class="p">(</span><span class="n">BaseAttachments</span><span class="p">):</span>
    <span class="n">_endpoints</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;attachments&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/attachments&#39;</span><span class="p">,</span>
        <span class="s1">&#39;attachment&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/attachments/</span><span class="si">{ida}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_mime&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/attachments/</span><span class="si">{ida}</span><span class="s1">/$value&#39;</span><span class="p">,</span>
    <span class="p">}</span>
    <span class="n">_attachment_constructor</span> <span class="o">=</span> <span class="n">MessageAttachment</span>

<div class="viewcode-block" id="MessageAttachments.save_as_eml"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MessageAttachments.save_as_eml">[docs]</a>    <span class="k">def</span> <span class="nf">save_as_eml</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attachment</span><span class="p">,</span> <span class="n">to_path</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Saves this message as and EML to the file system</span>
<span class="sd">        :param MessageAttachment attachment: the MessageAttachment to store as eml.</span>
<span class="sd">        :param Path or str to_path: the path where to store this file</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">attachment</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">attachment</span><span class="p">,</span> <span class="n">MessageAttachment</span><span class="p">)</span> \
                <span class="ow">or</span> <span class="n">attachment</span><span class="o">.</span><span class="n">attachment_id</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">attachment</span><span class="o">.</span><span class="n">attachment_type</span> <span class="o">!=</span> <span class="s1">&#39;item&#39;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Must provide a saved &quot;item&quot; attachment of type MessageAttachment&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">to_path</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">to_path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">&#39;message_eml.eml&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">to_path</span><span class="p">,</span> <span class="n">Path</span><span class="p">):</span>
                <span class="n">to_path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">to_path</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">to_path</span><span class="o">.</span><span class="n">suffix</span><span class="p">:</span>
            <span class="n">to_path</span> <span class="o">=</span> <span class="n">to_path</span><span class="o">.</span><span class="n">with_suffix</span><span class="p">(</span><span class="s1">&#39;.eml&#39;</span><span class="p">)</span>

        <span class="n">msg_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span><span class="o">.</span><span class="n">object_id</span>
        <span class="k">if</span> <span class="n">msg_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Attempting to get the mime contents of an unsaved message&#39;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_mime&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="n">msg_id</span><span class="p">,</span> <span class="n">ida</span><span class="o">=</span><span class="n">attachment</span><span class="o">.</span><span class="n">attachment_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">mime_content</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span>

        <span class="k">if</span> <span class="n">mime_content</span><span class="p">:</span>
            <span class="k">with</span> <span class="n">to_path</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">file_obj</span><span class="p">:</span>
                <span class="n">file_obj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">mime_content</span><span class="p">)</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">return</span> <span class="kc">False</span></div></div>


<div class="viewcode-block" id="MessageFlag"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MessageFlag">[docs]</a><span class="k">class</span> <span class="nc">MessageFlag</span><span class="p">(</span><span class="n">ApiComponent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; A flag on a message &quot;&quot;&quot;</span>

<div class="viewcode-block" id="MessageFlag.__init__"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MessageFlag.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">flag_data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; An flag on a message</span>
<span class="sd">        Not available on Outlook Rest Api v2 (only in beta)</span>

<span class="sd">        :param parent: parent of this</span>
<span class="sd">        :type parent: Message</span>
<span class="sd">        :param dict flag_data: flag data from cloud</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">protocol</span><span class="o">=</span><span class="n">parent</span><span class="o">.</span><span class="n">protocol</span><span class="p">,</span>
                         <span class="n">main_resource</span><span class="o">=</span><span class="n">parent</span><span class="o">.</span><span class="n">main_resource</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__message</span> <span class="o">=</span> <span class="n">parent</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__status</span> <span class="o">=</span> <span class="n">Flag</span><span class="o">.</span><span class="n">from_value</span><span class="p">(</span><span class="n">flag_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;flagStatus&#39;</span><span class="p">),</span> <span class="s1">&#39;notFlagged&#39;</span><span class="p">))</span>

        <span class="n">start_obj</span> <span class="o">=</span> <span class="n">flag_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;startDateTime&#39;</span><span class="p">),</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__start</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_date_time_time_zone</span><span class="p">(</span><span class="n">start_obj</span><span class="p">)</span>

        <span class="n">due_date_obj</span> <span class="o">=</span> <span class="n">flag_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;dueDateTime&#39;</span><span class="p">),</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__due_date</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_date_time_time_zone</span><span class="p">(</span><span class="n">due_date_obj</span><span class="p">)</span>

        <span class="n">completed_date_obj</span> <span class="o">=</span> <span class="n">flag_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;completedDateTime&#39;</span><span class="p">),</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__completed</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_date_time_time_zone</span><span class="p">(</span><span class="n">completed_date_obj</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__status</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__repr__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__bool__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_flagged</span>

    <span class="k">def</span> <span class="nf">_track_changes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Update the track_changes on the message to reflect a</span>
<span class="sd">        needed update on this field &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__message</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;flag&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">status</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__status</span>

<div class="viewcode-block" id="MessageFlag.set_flagged"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MessageFlag.set_flagged">[docs]</a>    <span class="k">def</span> <span class="nf">set_flagged</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">start_date</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">due_date</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Sets this message as flagged</span>
<span class="sd">        :param start_date: the start datetime of the followUp</span>
<span class="sd">        :param due_date: the due datetime of the followUp</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__status</span> <span class="o">=</span> <span class="n">Flag</span><span class="o">.</span><span class="n">Flagged</span>
        <span class="n">start_date</span> <span class="o">=</span> <span class="n">start_date</span> <span class="ow">or</span> <span class="n">dt</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
        <span class="n">due_date</span> <span class="o">=</span> <span class="n">due_date</span> <span class="ow">or</span> <span class="n">dt</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">start_date</span><span class="o">.</span><span class="n">tzinfo</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">start_date</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span><span class="o">.</span><span class="n">localize</span><span class="p">(</span><span class="n">start_date</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">due_date</span><span class="o">.</span><span class="n">tzinfo</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">due_date</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span><span class="o">.</span><span class="n">localize</span><span class="p">(</span><span class="n">due_date</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__start</span> <span class="o">=</span> <span class="n">start_date</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__due_date</span> <span class="o">=</span> <span class="n">due_date</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="p">()</span></div>

<div class="viewcode-block" id="MessageFlag.set_completed"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MessageFlag.set_completed">[docs]</a>    <span class="k">def</span> <span class="nf">set_completed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">completition_date</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Sets this message flag as completed</span>
<span class="sd">        :param completition_date: the datetime this followUp was completed</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__status</span> <span class="o">=</span> <span class="n">Flag</span><span class="o">.</span><span class="n">Complete</span>
        <span class="n">completition_date</span> <span class="o">=</span> <span class="n">completition_date</span> <span class="ow">or</span> <span class="n">dt</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">completition_date</span><span class="o">.</span><span class="n">tzinfo</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">completition_date</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span><span class="o">.</span><span class="n">localize</span><span class="p">(</span><span class="n">completition_date</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__completed</span> <span class="o">=</span> <span class="n">completition_date</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="p">()</span></div>

<div class="viewcode-block" id="MessageFlag.delete_flag"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MessageFlag.delete_flag">[docs]</a>    <span class="k">def</span> <span class="nf">delete_flag</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Sets this message as un flagged &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__status</span> <span class="o">=</span> <span class="n">Flag</span><span class="o">.</span><span class="n">NotFlagged</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__start</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__due_date</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__completed</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="p">()</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">start_date</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__start</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">due_date</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__due_date</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">completition_date</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__completed</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_completed</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__status</span> <span class="ow">is</span> <span class="n">Flag</span><span class="o">.</span><span class="n">Complete</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_flagged</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__status</span> <span class="ow">is</span> <span class="n">Flag</span><span class="o">.</span><span class="n">Flagged</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">__status</span> <span class="ow">is</span> <span class="n">Flag</span><span class="o">.</span><span class="n">Complete</span>

<div class="viewcode-block" id="MessageFlag.to_api_data"><a class="viewcode-back" href="../../api/message.html#O365.address_book.MessageFlag.to_api_data">[docs]</a>    <span class="k">def</span> <span class="nf">to_api_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns this data as a dict to be sent to the server &quot;&quot;&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;flagStatus&#39;</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__status</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
        <span class="p">}</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__status</span> <span class="ow">is</span> <span class="n">Flag</span><span class="o">.</span><span class="n">Flagged</span><span class="p">:</span>
            <span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;startDateTime&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_build_date_time_time_zone</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__start</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__start</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
            <span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;dueDateTime&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_build_date_time_time_zone</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__due_date</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__due_date</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__status</span> <span class="ow">is</span> <span class="n">Flag</span><span class="o">.</span><span class="n">Complete</span><span class="p">:</span>
            <span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;completedDateTime&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_build_date_time_time_zone</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__completed</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">data</span></div></div>


<div class="viewcode-block" id="Message"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message">[docs]</a><span class="k">class</span> <span class="nc">Message</span><span class="p">(</span><span class="n">ApiComponent</span><span class="p">,</span> <span class="n">AttachableMixin</span><span class="p">,</span> <span class="n">HandleRecipientsMixin</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Management of the process of sending, receiving, reading, and</span>
<span class="sd">    editing emails. &quot;&quot;&quot;</span>

    <span class="n">_endpoints</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;create_draft&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages&#39;</span><span class="p">,</span>
        <span class="s1">&#39;create_draft_folder&#39;</span><span class="p">:</span> <span class="s1">&#39;/mailFolders/</span><span class="si">{id}</span><span class="s1">/messages&#39;</span><span class="p">,</span>
        <span class="s1">&#39;send_mail&#39;</span><span class="p">:</span> <span class="s1">&#39;/sendMail&#39;</span><span class="p">,</span>
        <span class="s1">&#39;send_draft&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/send&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_message&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;move_message&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/move&#39;</span><span class="p">,</span>
        <span class="s1">&#39;copy_message&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/copy&#39;</span><span class="p">,</span>
        <span class="s1">&#39;create_reply&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/createReply&#39;</span><span class="p">,</span>
        <span class="s1">&#39;create_reply_all&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/createReplyAll&#39;</span><span class="p">,</span>
        <span class="s1">&#39;forward_message&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/createForward&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_mime&#39;</span><span class="p">:</span> <span class="s1">&#39;/messages/</span><span class="si">{id}</span><span class="s1">/$value&#39;</span><span class="p">,</span>
    <span class="p">}</span>

<div class="viewcode-block" id="Message.__init__"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">con</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Makes a new message wrapper for sending and receiving messages.</span>

<span class="sd">        :param parent: parent folder/account to create the message in</span>
<span class="sd">        :type parent: mailbox.Folder or Account</span>
<span class="sd">        :param Connection con: connection to use if no parent specified</span>
<span class="sd">        :param Protocol protocol: protocol to use if no parent specified</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        :param str main_resource: use this resource instead of parent resource</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        :param bool download_attachments: whether or not to</span>
<span class="sd">         download attachments (kwargs)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">parent</span> <span class="ow">and</span> <span class="n">con</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Need a parent or a connection but not both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">con</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">con</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">con</span>

        <span class="c1"># Choose the main_resource passed in kwargs over parent main_resource</span>
        <span class="n">main_resource</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span>
            <span class="nb">getattr</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span>

        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">protocol</span><span class="o">=</span><span class="n">parent</span><span class="o">.</span><span class="n">protocol</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;protocol&#39;</span><span class="p">),</span>
            <span class="n">main_resource</span><span class="o">=</span><span class="n">main_resource</span><span class="p">,</span>
            <span class="n">attachment_name_property</span><span class="o">=</span><span class="s1">&#39;subject&#39;</span><span class="p">,</span> <span class="n">attachment_type</span><span class="o">=</span><span class="s1">&#39;message_type&#39;</span><span class="p">)</span>

        <span class="n">download_attachments</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;download_attachments&#39;</span><span class="p">)</span>

        <span class="n">cloud_data</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">,</span> <span class="p">{})</span>
        <span class="n">cc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span>  <span class="c1"># alias to shorten the code</span>

        <span class="c1"># internal to know which properties need to be updated on the server</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span> <span class="o">=</span> <span class="n">TrackerSet</span><span class="p">(</span><span class="n">casing</span><span class="o">=</span><span class="n">cc</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">),</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;object_id&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__created</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;createdDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__modified</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;lastModifiedDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__received</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;receivedDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__sent</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;sentDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>

        <span class="n">local_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__created</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__created</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
            <span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__created</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__modified</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__modified</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
            <span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__modified</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__received</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__received</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
            <span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__received</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__sent</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__sent</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
            <span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__sent</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__attachments</span> <span class="o">=</span> <span class="n">MessageAttachments</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">attachments</span><span class="o">=</span><span class="p">[])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__attachments</span><span class="o">.</span><span class="n">add</span><span class="p">({</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;attachments&#39;</span><span class="p">),</span> <span class="p">[])})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">has_attachments</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;hasAttachments&#39;</span><span class="p">),</span> <span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__subject</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;subject&#39;</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__body_preview</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;bodyPreview&#39;</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="n">body</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;body&#39;</span><span class="p">),</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__body</span> <span class="o">=</span> <span class="n">body</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;content&#39;</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">body_type</span> <span class="o">=</span> <span class="n">body</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;contentType&#39;</span><span class="p">),</span> <span class="s1">&#39;HTML&#39;</span><span class="p">)</span>  <span class="c1"># default to HTML for new messages</span>

        <span class="n">unique_body</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;uniqueBody&#39;</span><span class="p">),</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__unique_body</span> <span class="o">=</span> <span class="n">unique_body</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;content&#39;</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">unique_body_type</span> <span class="o">=</span> <span class="n">unique_body</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;contentType&#39;</span><span class="p">),</span> <span class="s1">&#39;HTML&#39;</span><span class="p">)</span>  <span class="c1"># default to HTML for new messages</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_attachments</span> <span class="ow">is</span> <span class="kc">False</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">body_type</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;HTML&#39;</span><span class="p">:</span>
            <span class="c1"># test for inline attachments (Azure responds with hasAttachments=False when there are only inline attachments):</span>
            <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">img</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;src&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;cid:&#39;</span><span class="p">)</span> <span class="k">for</span> <span class="n">img</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_body_soup</span><span class="p">()</span><span class="o">.</span><span class="n">find_all</span><span class="p">(</span><span class="s1">&#39;img&#39;</span><span class="p">)):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">has_attachments</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_attachments</span> <span class="ow">and</span> <span class="n">download_attachments</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">attachments</span><span class="o">.</span><span class="n">download_attachments</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__sender</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_recipient_from_cloud</span><span class="p">(</span>
            <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;from&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">),</span> <span class="n">field</span><span class="o">=</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;from&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__to</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_recipients_from_cloud</span><span class="p">(</span>
            <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;toRecipients&#39;</span><span class="p">),</span> <span class="p">[]),</span> <span class="n">field</span><span class="o">=</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;toRecipients&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__cc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_recipients_from_cloud</span><span class="p">(</span>
            <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;ccRecipients&#39;</span><span class="p">),</span> <span class="p">[]),</span> <span class="n">field</span><span class="o">=</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;ccRecipients&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__bcc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_recipients_from_cloud</span><span class="p">(</span>
            <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;bccRecipients&#39;</span><span class="p">),</span> <span class="p">[]),</span> <span class="n">field</span><span class="o">=</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;bccRecipients&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__reply_to</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_recipients_from_cloud</span><span class="p">(</span>
            <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;replyTo&#39;</span><span class="p">),</span> <span class="p">[]),</span> <span class="n">field</span><span class="o">=</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;replyTo&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__categories</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;categories&#39;</span><span class="p">),</span> <span class="p">[])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__importance</span> <span class="o">=</span> <span class="n">ImportanceLevel</span><span class="o">.</span><span class="n">from_value</span><span class="p">(</span><span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;importance&#39;</span><span class="p">),</span> <span class="s1">&#39;normal&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="s1">&#39;normal&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__is_read</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;isRead&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__is_read_receipt_requested</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;isReadReceiptRequested&#39;</span><span class="p">),</span> <span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__is_delivery_receipt_requested</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;isDeliveryReceiptRequested&#39;</span><span class="p">),</span> <span class="kc">False</span><span class="p">)</span>

        <span class="c1"># if this message is an EventMessage:</span>
        <span class="n">meeting_mt</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;meetingMessageType&#39;</span><span class="p">),</span> <span class="s1">&#39;none&#39;</span><span class="p">)</span>

        <span class="c1"># hack to avoid typo in EventMessage between Api v1.0 and beta:</span>
        <span class="n">meeting_mt</span> <span class="o">=</span> <span class="n">meeting_mt</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;Tenatively&#39;</span><span class="p">,</span> <span class="s1">&#39;Tentatively&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__meeting_message_type</span> <span class="o">=</span> <span class="n">MeetingMessageType</span><span class="o">.</span><span class="n">from_value</span><span class="p">(</span><span class="n">meeting_mt</span><span class="p">)</span> <span class="k">if</span> <span class="n">meeting_mt</span> <span class="o">!=</span> <span class="s1">&#39;none&#39;</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="c1"># a message is a draft by default</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;isDraft&#39;</span><span class="p">),</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;is_draft&#39;</span><span class="p">,</span>
                                                                   <span class="kc">True</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">conversation_id</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;conversationId&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">conversation_index</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;conversationIndex&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">folder_id</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;parentFolderId&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>

        <span class="n">flag_data</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;flag&#39;</span><span class="p">),</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__flag</span> <span class="o">=</span> <span class="n">MessageFlag</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">flag_data</span><span class="o">=</span><span class="n">flag_data</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">internet_message_id</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;internetMessageId&#39;</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">web_link</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;webLink&#39;</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>

        <span class="c1"># Headers only retrieved when selecting &#39;internetMessageHeaders&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">message_headers</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;internetMessageHeaders&#39;</span><span class="p">),</span> <span class="p">[])</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__repr__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;Subject: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">subject</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">object_id</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_read</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Check if the message is read or not</span>

<span class="sd">        :getter: Get the status of message read</span>
<span class="sd">        :setter: Mark the message as read</span>
<span class="sd">        :type: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_read</span>

    <span class="nd">@is_read</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">is_read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__is_read</span> <span class="o">=</span> <span class="n">value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;isRead&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_draft</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Check if the message is marked as draft</span>

<span class="sd">        :type: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">subject</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Subject of the email message</span>

<span class="sd">        :getter: Get the current subject</span>
<span class="sd">        :setter: Assign a new subject</span>
<span class="sd">        :type: str</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__subject</span>

    <span class="nd">@subject</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">subject</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__subject</span> <span class="o">=</span> <span class="n">value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;subject&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">body_preview</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns the body preview &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__body_preview</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">body</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Body of the email message</span>

<span class="sd">        :getter: Get body text of current message</span>
<span class="sd">        :setter: set html body of the message</span>
<span class="sd">        :type: str</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__body</span>

    <span class="nd">@body</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">body</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__body</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">value</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__body</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">body_type</span> <span class="o">==</span> <span class="s1">&#39;html&#39;</span><span class="p">:</span>
                <span class="n">soup</span> <span class="o">=</span> <span class="n">bs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__body</span><span class="p">,</span> <span class="s1">&#39;html.parser&#39;</span><span class="p">)</span>
                <span class="n">soup</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">bs</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s1">&#39;html.parser&#39;</span><span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__body</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">soup</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__body</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">value</span><span class="p">,</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__body</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__body</span> <span class="o">=</span> <span class="n">value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;body&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">unique_body</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; The unique body of this message</span>
<span class="sd">            Requires a select to retrieve it.</span>
<span class="sd">        :rtype: str</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__unique_body</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">created</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Created time of the message &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__created</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">modified</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Message last modified time &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__modified</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">received</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Message received time&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__received</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">sent</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Message sent time&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__sent</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">attachments</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; List of attachments &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__attachments</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">sender</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Sender of the message</span>

<span class="sd">        :getter: Get the current sender</span>
<span class="sd">        :setter: Update the from address with new value</span>
<span class="sd">        :type: str or Recipient</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__sender</span>

    <span class="nd">@sender</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">sender</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; sender is a property to force to be always a Recipient class &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Recipient</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">_parent</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">value</span><span class="o">.</span><span class="n">_parent</span> <span class="o">=</span> <span class="bp">self</span>
                <span class="n">value</span><span class="o">.</span><span class="n">_field</span> <span class="o">=</span> <span class="s1">&#39;from&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__sender</span> <span class="o">=</span> <span class="n">value</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__sender</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="n">value</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__sender</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s1">&#39;sender must be an address string or a Recipient object&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;from&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">to</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; &#39;TO&#39; list of recipients &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__to</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">cc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; &#39;CC&#39; list of recipients &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__cc</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bcc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; &#39;BCC&#39; list of recipients &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__bcc</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">reply_to</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Reply to address &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__reply_to</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">categories</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Categories of this message</span>

<span class="sd">        :getter: Current list of categories</span>
<span class="sd">        :setter: Set new categories for the message</span>
<span class="sd">        :type: list[str] or str</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__categories</span>

    <span class="nd">@categories</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">categories</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__categories</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">Category</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">__categories</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">val</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">__categories</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__categories</span> <span class="o">=</span> <span class="p">[</span><span class="n">value</span><span class="p">]</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Category</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__categories</span> <span class="o">=</span> <span class="p">[</span><span class="n">value</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;categories must be a list&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;categories&#39;</span><span class="p">)</span>

<div class="viewcode-block" id="Message.add_category"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.add_category">[docs]</a>    <span class="k">def</span> <span class="nf">add_category</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">category</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Adds a category to this message current categories list &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">category</span><span class="p">,</span> <span class="n">Category</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__categories</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">category</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__categories</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">category</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;categories&#39;</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">importance</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Importance of the message</span>

<span class="sd">        :getter: Get the current priority of the message</span>
<span class="sd">        :setter: Set a different importance level</span>
<span class="sd">        :type: str or ImportanceLevel</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__importance</span>

    <span class="nd">@importance</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">importance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__importance</span> <span class="o">=</span> <span class="p">(</span><span class="n">value</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">ImportanceLevel</span><span class="p">)</span>
                             <span class="k">else</span> <span class="n">ImportanceLevel</span><span class="o">.</span><span class="n">from_value</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;importance&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_read_receipt_requested</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; if the read receipt is requested for this message</span>

<span class="sd">        :getter: Current state of isReadReceiptRequested</span>
<span class="sd">        :setter: Set isReadReceiptRequested for the message</span>
<span class="sd">        :type: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_read_receipt_requested</span>

    <span class="nd">@is_read_receipt_requested</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">is_read_receipt_requested</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__is_read_receipt_requested</span> <span class="o">=</span> <span class="nb">bool</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;isReadReceiptRequested&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_delivery_receipt_requested</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; if the delivery receipt is requested for this message</span>

<span class="sd">        :getter: Current state of isDeliveryReceiptRequested</span>
<span class="sd">        :setter: Set isDeliveryReceiptRequested for the message</span>
<span class="sd">        :type: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_delivery_receipt_requested</span>

    <span class="nd">@is_delivery_receipt_requested</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">is_delivery_receipt_requested</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__is_delivery_receipt_requested</span> <span class="o">=</span> <span class="nb">bool</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;isDeliveryReceiptRequested&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">meeting_message_type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; If this message is a EventMessage, returns the</span>
<span class="sd">        meeting type: meetingRequest, meetingCancelled, meetingAccepted,</span>
<span class="sd">            meetingTentativelyAccepted, meetingDeclined</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__meeting_message_type</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_event_message</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns if this message is of type EventMessage</span>
<span class="sd">        and therefore can return the related event.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__meeting_message_type</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">flag</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; The Message Flag instance &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__flag</span>

<div class="viewcode-block" id="Message.to_api_data"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.to_api_data">[docs]</a>    <span class="k">def</span> <span class="nf">to_api_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">restrict_keys</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a dict representation of this message prepared to be send</span>
<span class="sd">        to the cloud</span>

<span class="sd">        :param restrict_keys: a set of keys to restrict the returned</span>
<span class="sd">         data to</span>
<span class="sd">        :type restrict_keys: dict or set</span>
<span class="sd">        :return: converted to cloud based keys</span>
<span class="sd">        :rtype: dict</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">cc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span>  <span class="c1"># alias to shorten the code</span>

        <span class="n">message</span> <span class="o">=</span> <span class="p">{</span>
            <span class="n">cc</span><span class="p">(</span><span class="s1">&#39;subject&#39;</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span>
            <span class="n">cc</span><span class="p">(</span><span class="s1">&#39;body&#39;</span><span class="p">):</span> <span class="p">{</span>
                <span class="n">cc</span><span class="p">(</span><span class="s1">&#39;contentType&#39;</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">body_type</span><span class="p">,</span>
                <span class="n">cc</span><span class="p">(</span><span class="s1">&#39;content&#39;</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">body</span><span class="p">},</span>
            <span class="n">cc</span><span class="p">(</span><span class="s1">&#39;importance&#39;</span><span class="p">):</span> <span class="n">cc</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">importance</span><span class="o">.</span><span class="n">value</span><span class="p">),</span>
            <span class="n">cc</span><span class="p">(</span><span class="s1">&#39;flag&#39;</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">flag</span><span class="o">.</span><span class="n">to_api_data</span><span class="p">(),</span>
            <span class="n">cc</span><span class="p">(</span><span class="s1">&#39;isReadReceiptRequested&#39;</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_read_receipt_requested</span><span class="p">,</span>
            <span class="n">cc</span><span class="p">(</span><span class="s1">&#39;isDeliveryReceiptRequested&#39;</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_delivery_receipt_requested</span><span class="p">,</span>
        <span class="p">}</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">to</span><span class="p">:</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;toRecipients&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_recipient_to_cloud</span><span class="p">(</span><span class="n">recipient</span><span class="p">)</span>
                                           <span class="k">for</span> <span class="n">recipient</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">to</span><span class="p">]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cc</span><span class="p">:</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;ccRecipients&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_recipient_to_cloud</span><span class="p">(</span><span class="n">recipient</span><span class="p">)</span>
                                           <span class="k">for</span> <span class="n">recipient</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cc</span><span class="p">]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bcc</span><span class="p">:</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;bccRecipients&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_recipient_to_cloud</span><span class="p">(</span><span class="n">recipient</span><span class="p">)</span>
                                            <span class="k">for</span> <span class="n">recipient</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bcc</span><span class="p">]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">reply_to</span><span class="p">:</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;replyTo&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_recipient_to_cloud</span><span class="p">(</span><span class="n">recipient</span><span class="p">)</span> <span class="k">for</span>
                                      <span class="n">recipient</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">reply_to</span><span class="p">]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">attachments</span><span class="p">:</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;attachments&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">attachments</span><span class="o">.</span><span class="n">to_api_data</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sender</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">sender</span><span class="o">.</span><span class="n">address</span><span class="p">:</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;from&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_recipient_to_cloud</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sender</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">categories</span> <span class="ow">or</span> <span class="s1">&#39;categories&#39;</span> <span class="ow">in</span> <span class="p">(</span><span class="n">restrict_keys</span> <span class="ow">or</span> <span class="p">{}):</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;categories&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">categories</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span><span class="p">:</span>
            <span class="c1"># return the whole signature of this message</span>

            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">created</span><span class="p">:</span>
                <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;createdDateTime&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">created</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
                    <span class="n">pytz</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span><span class="o">.</span><span class="n">isoformat</span><span class="p">()</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">received</span><span class="p">:</span>
                <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;receivedDateTime&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">received</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
                    <span class="n">pytz</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span><span class="o">.</span><span class="n">isoformat</span><span class="p">()</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sent</span><span class="p">:</span>
                <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;sentDateTime&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sent</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
                    <span class="n">pytz</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span><span class="o">.</span><span class="n">isoformat</span><span class="p">()</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;hasAttachments&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">attachments</span><span class="p">)</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;isRead&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_read</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;isDraft&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;conversationId&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">conversation_id</span>
            <span class="c1"># this property does not form part of the message itself</span>
            <span class="n">message</span><span class="p">[</span><span class="n">cc</span><span class="p">(</span><span class="s1">&#39;parentFolderId&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">folder_id</span>

        <span class="k">if</span> <span class="n">restrict_keys</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
                <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">restrict_keys</span><span class="p">:</span>
                    <span class="k">del</span> <span class="n">message</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">message</span></div>

<div class="viewcode-block" id="Message.send"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.send">[docs]</a>    <span class="k">def</span> <span class="nf">send</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">save_to_sent_folder</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Sends this message</span>

<span class="sd">        :param bool save_to_sent_folder: whether or not to save it to</span>
<span class="sd">         sent folder</span>
<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span><span class="p">:</span>
            <span class="k">return</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Not possible to send a message that is not &#39;</span>
                                <span class="s1">&#39;new or a draft. Use Reply or Forward instead.&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;send_draft&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="p">:</span>
                <span class="c1"># there are pending changes to be committed</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">save_draft</span><span class="p">()</span>
            <span class="n">data</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;send_mail&#39;</span><span class="p">))</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;message&#39;</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_api_data</span><span class="p">()}</span>
            <span class="k">if</span> <span class="n">save_to_sent_folder</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">:</span>
                <span class="n">data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;saveToSentItems&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="c1"># response evaluates to false if 4XX or 5XX status codes are returned</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="s1">&#39;sent_message&#39;</span> <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> \
            <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Message.reply"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.reply">[docs]</a>    <span class="k">def</span> <span class="nf">reply</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">to_all</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;  Creates a new message that is a reply to this message</span>

<span class="sd">        :param bool to_all: whether or not to replies to all the recipients</span>
<span class="sd">         instead to just the sender</span>
<span class="sd">        :return: new message</span>
<span class="sd">        :rtype: Message</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Can&#39;t reply to this message&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">to_all</span><span class="p">:</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;create_reply_all&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;create_reply&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">message</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">message</span><span class="p">})</span></div>

<div class="viewcode-block" id="Message.forward"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.forward">[docs]</a>    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;  Creates a new message that is a forward this message</span>

<span class="sd">        :return: new message</span>
<span class="sd">        :rtype: Message</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Can&#39;t forward this message&quot;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;forward_message&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">message</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">message</span><span class="p">})</span></div>

<div class="viewcode-block" id="Message.delete"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.delete">[docs]</a>    <span class="k">def</span> <span class="nf">delete</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Deletes a stored message</span>

<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Attempting to delete an unsaved Message&#39;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_message&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>

        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="n">response</span><span class="p">)</span></div>

<div class="viewcode-block" id="Message.mark_as_read"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.mark_as_read">[docs]</a>    <span class="k">def</span> <span class="nf">mark_as_read</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Marks this message as read in the cloud</span>

<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Attempting to mark as read an unsaved Message&#39;</span><span class="p">)</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;isRead&#39;</span><span class="p">):</span> <span class="kc">True</span><span class="p">}</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_message&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">patch</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__is_read</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Message.mark_as_unread"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.mark_as_unread">[docs]</a>    <span class="k">def</span> <span class="nf">mark_as_unread</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Marks this message as unread in the cloud</span>

<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Attempting to mark as unread an unsaved Message&#39;</span><span class="p">)</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;isRead&#39;</span><span class="p">):</span> <span class="kc">False</span><span class="p">}</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_message&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">patch</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__is_read</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Message.move"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.move">[docs]</a>    <span class="k">def</span> <span class="nf">move</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">folder</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Move the message to a given folder</span>

<span class="sd">        :param folder: Folder object or Folder id or Well-known name to</span>
<span class="sd">         move this message to</span>
<span class="sd">        :type folder: str or mailbox.Folder</span>
<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Attempting to move an unsaved Message&#39;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;move_message&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">folder</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">folder_id</span> <span class="o">=</span> <span class="n">folder</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">folder_id</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">folder</span><span class="p">,</span> <span class="s1">&#39;folder_id&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">folder_id</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Must Provide a valid folder_id&#39;</span><span class="p">)</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;destinationId&#39;</span><span class="p">):</span> <span class="n">folder_id</span><span class="p">}</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">message</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">folder_id</span> <span class="o">=</span> <span class="n">folder_id</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">)</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Message.copy"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.copy">[docs]</a>    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">folder</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Copy the message to a given folder</span>

<span class="sd">        :param folder: Folder object or Folder id or Well-known name to</span>
<span class="sd">         copy this message to</span>
<span class="sd">        :type folder: str or mailbox.Folder</span>
<span class="sd">        :returns: the copied message</span>
<span class="sd">        :rtype: Message</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Attempting to move an unsaved Message&#39;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;copy_message&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">folder</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">folder_id</span> <span class="o">=</span> <span class="n">folder</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">folder_id</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">folder</span><span class="p">,</span> <span class="s1">&#39;folder_id&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">folder_id</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Must Provide a valid folder_id&#39;</span><span class="p">)</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;destinationId&#39;</span><span class="p">):</span> <span class="n">folder_id</span><span class="p">}</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">message</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">message</span><span class="p">})</span></div>

<div class="viewcode-block" id="Message.save_message"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.save_message">[docs]</a>    <span class="k">def</span> <span class="nf">save_message</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Saves changes to a message.</span>
<span class="sd">        If the message is a new or saved draft it will call &#39;save_draft&#39; otherwise</span>
<span class="sd">        this will save only properties of a message that are draft-independent such as:</span>
<span class="sd">            - is_read</span>
<span class="sd">            - category</span>
<span class="sd">            - flag</span>
<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span><span class="p">:</span>
            <span class="c1"># we are only allowed to save some properties:</span>
            <span class="n">allowed_changes</span> <span class="o">=</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;isRead&#39;</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;categories&#39;</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;flag&#39;</span><span class="p">)}</span>  <span class="c1"># allowed changes to be saved by this method</span>
            <span class="n">changes</span> <span class="o">=</span> <span class="p">{</span><span class="n">tc</span> <span class="k">for</span> <span class="n">tc</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span> <span class="k">if</span> <span class="n">tc</span> <span class="ow">in</span> <span class="n">allowed_changes</span><span class="p">}</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="n">changes</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">True</span>  <span class="c1"># there&#39;s nothing to update</span>

            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_message&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

            <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_api_data</span><span class="p">(</span><span class="n">restrict_keys</span><span class="o">=</span><span class="n">changes</span><span class="p">)</span>

            <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">patch</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">False</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>  <span class="c1"># reset the tracked changes as they are all saved</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__modified</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span><span class="o">.</span><span class="n">localize</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>

            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># fallback to save_draft</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">save_draft</span><span class="p">()</span></div>

<div class="viewcode-block" id="Message.save_draft"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.save_draft">[docs]</a>    <span class="k">def</span> <span class="nf">save_draft</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target_folder</span><span class="o">=</span><span class="n">OutlookWellKnowFolderNames</span><span class="o">.</span><span class="n">DRAFTS</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Save this message as a draft on the cloud</span>

<span class="sd">        :param target_folder: name of the drafts folder</span>
<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="c1"># update message. Attachments are NOT included nor saved.</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Only draft messages can be updated&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">True</span>  <span class="c1"># there&#39;s nothing to update</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_message&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>
            <span class="n">method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">patch</span>
            <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_api_data</span><span class="p">(</span><span class="n">restrict_keys</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="p">)</span>

            <span class="n">data</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;attachments&#39;</span><span class="p">),</span>
                     <span class="kc">None</span><span class="p">)</span>  <span class="c1"># attachments are handled by the next method call</span>
            <span class="c1"># noinspection PyProtectedMember</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">attachments</span><span class="o">.</span><span class="n">_update_attachments_to_cloud</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># new message. Attachments are included and saved.</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__is_draft</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Only draft messages can be saved as drafts&#39;</span><span class="p">)</span>

            <span class="n">target_folder</span> <span class="o">=</span> <span class="n">target_folder</span> <span class="ow">or</span> <span class="n">OutlookWellKnowFolderNames</span><span class="o">.</span><span class="n">DRAFTS</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">target_folder</span><span class="p">,</span> <span class="n">OutlookWellKnowFolderNames</span><span class="p">):</span>
                <span class="n">target_folder</span> <span class="o">=</span> <span class="n">target_folder</span><span class="o">.</span><span class="n">value</span>
            <span class="k">elif</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">target_folder</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="c1"># a Folder instance</span>
                <span class="n">target_folder</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">target_folder</span><span class="p">,</span> <span class="s1">&#39;folder_id&#39;</span><span class="p">,</span>
                                        <span class="n">OutlookWellKnowFolderNames</span><span class="o">.</span><span class="n">DRAFTS</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>

            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;create_draft_folder&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="nb">id</span><span class="o">=</span><span class="n">target_folder</span><span class="p">))</span>
            <span class="n">method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span>
            <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_api_data</span><span class="p">()</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">True</span>

        <span class="n">response</span> <span class="o">=</span> <span class="n">method</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_track_changes</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>  <span class="c1"># reset the tracked changes as they are all saved</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="c1"># new message</span>
            <span class="n">message</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">folder_id</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;parentFolderId&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>

            <span class="c1"># fallback to office365 v1.0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__created</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;createdDateTime&#39;</span><span class="p">),</span>
                                         <span class="n">message</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                                             <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;dateTimeCreated&#39;</span><span class="p">),</span>
                                             <span class="kc">None</span><span class="p">))</span>
            <span class="c1"># fallback to office365 v1.0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__modified</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;lastModifiedDateTime&#39;</span><span class="p">),</span>
                                          <span class="n">message</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                                              <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;dateTimeModified&#39;</span><span class="p">),</span>
                                              <span class="kc">None</span><span class="p">))</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">__created</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__created</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__created</span> <span class="k">else</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__modified</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__modified</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__modified</span> <span class="k">else</span> <span class="kc">None</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">web_link</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;webLink&#39;</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__modified</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span><span class="o">.</span><span class="n">localize</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Message.get_body_text"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.get_body_text">[docs]</a>    <span class="k">def</span> <span class="nf">get_body_text</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Parse the body html and returns the body text using bs4</span>

<span class="sd">        :return: body as text</span>
<span class="sd">        :rtype: str</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">body_type</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">!=</span> <span class="s1">&#39;HTML&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">body</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">soup</span> <span class="o">=</span> <span class="n">bs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">body</span><span class="p">,</span> <span class="s1">&#39;html.parser&#39;</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">RuntimeError</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">body</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">soup</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">text</span></div>

<div class="viewcode-block" id="Message.get_body_soup"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.get_body_soup">[docs]</a>    <span class="k">def</span> <span class="nf">get_body_soup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns the beautifulsoup4 of the html body</span>

<span class="sd">        :return: BeautifulSoup object of body</span>
<span class="sd">        :rtype: BeautifulSoup</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">body_type</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">!=</span> <span class="s1">&#39;HTML&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">bs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">body</span><span class="p">,</span> <span class="s1">&#39;html.parser&#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Message.get_event"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.get_event">[docs]</a>    <span class="k">def</span> <span class="nf">get_event</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; If this is a EventMessage it should return the related Event&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_event_message</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="c1"># select a dummy field (eg. subject) to avoid pull unneccesary data</span>
        <span class="n">query</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s1">&#39;subject&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="s1">&#39;event&#39;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_message&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">query</span><span class="o">.</span><span class="n">as_params</span><span class="p">())</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>
        <span class="n">event_data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;event&#39;</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">Event</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">event_data</span><span class="p">})</span></div>

<div class="viewcode-block" id="Message.get_mime_content"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.get_mime_content">[docs]</a>    <span class="k">def</span> <span class="nf">get_mime_content</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns the MIME contents of this message &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Attempting to get the mime contents of an unsaved message&#39;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_mime&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="k">return</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span></div>

<div class="viewcode-block" id="Message.save_as_eml"><a class="viewcode-back" href="../../api/message.html#O365.address_book.Message.save_as_eml">[docs]</a>    <span class="k">def</span> <span class="nf">save_as_eml</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">to_path</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Saves this message as and EML to the file system</span>
<span class="sd">        :param Path or str to_path: the path where to store this file</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">to_path</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">to_path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">&#39;message_eml.eml&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">to_path</span><span class="p">,</span> <span class="n">Path</span><span class="p">):</span>
                <span class="n">to_path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">to_path</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">to_path</span><span class="o">.</span><span class="n">suffix</span><span class="p">:</span>
            <span class="n">to_path</span> <span class="o">=</span> <span class="n">to_path</span><span class="o">.</span><span class="n">with_suffix</span><span class="p">(</span><span class="s1">&#39;.eml&#39;</span><span class="p">)</span>

        <span class="n">mime_content</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_mime_content</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">mime_content</span><span class="p">:</span>
            <span class="k">with</span> <span class="n">to_path</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">file_obj</span><span class="p">:</span>
                <span class="n">file_obj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">mime_content</span><span class="p">)</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">return</span> <span class="kc">False</span></div></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Narcolapser

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
    

  

  <script type="text/javascript" src="../../_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>